#include <g-bios.h>
#include <core/cmd.h>

#define DEF_GPN  13

static int main(int argc, char *argv[])
{
	static int bStatus = 0;
	UINT32 val;
	int nLedGpio;

	if (argc != 2 || (GuStrToVal(argv[1], &nLedGpio) < 0))
		nLedGpio = DEF_GPN;

	val = ReadLong(0x56000040);
	val &= ~(3 << (nLedGpio * 2));
	val |= 1 << (nLedGpio * 2);
	WriteLong(val, 0x56000040);

	val = ReadLong(0x56000044);
#if 1
	if (bStatus)
		val |= 1 << nLedGpio;
	else
		val &= ~(1 << nLedGpio);
#else
	val &= ~(1 << nLedGpio);
	val |= bStatus << nLedGpio;
#endif
	WriteLong(val, 0x56000044);

	bStatus = !bStatus;

	return 0;
}

INSTALL_APPLICATION(demo_led, main, "led demo");

